﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【安装地点】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto安装地点
    /// </summary>
    public abstract class AutoInstallAddressMapping : BaseMapping<InstallAddress, InstallAddressModel, InstallAddressFilterModel>
    {
        public AutoInstallAddressMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override InstallAddressModel Entity2Model(InstallAddress entity)
        {
            InstallAddressModel model = new InstallAddressModel();

            model.InstallAddressID = entity.InstallAddressID;
            model.GroupInfoID = entity.GroupInfoID;
            model.Code = entity.Code;
            model.AddressInfo = entity.AddressInfo;
            model.Remark = entity.Remark;
            model.IsDelete = entity.IsDelete;
            model.CreateUserID = entity.CreateUserID;
            model.CreateUserName = entity.CreateUserName;
            model.CreateDate = entity.CreateDate;
            model.UpdateUserID = entity.UpdateUserID;
            model.UpdateUserName = entity.UpdateUserName;
            model.UpdateDate = entity.UpdateDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override InstallAddress Model2Entity(InstallAddressModel model)
        {
            InstallAddress entity = new InstallAddress();

            entity.InstallAddressID = model.InstallAddressID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.Code = model.Code;
            entity.AddressInfo = model.AddressInfo;
            entity.Remark = model.Remark;
            entity.IsDelete = model.IsDelete;
            entity.CreateUserID = model.CreateUserID;
            entity.CreateUserName = model.CreateUserName;
            entity.CreateDate = model.CreateDate;
            entity.UpdateUserID = model.UpdateUserID;
            entity.UpdateUserName = model.UpdateUserName;
            entity.UpdateDate = model.UpdateDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<InstallAddress> FilterModel2Where(InstallAddressFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._InstallAddressID.HasValue)
            {
                where = where.And(x => x.InstallAddressID == filterModel._InstallAddressID.Value);
            }
            if (filterModel._InstallAddressIDs.IsNotEmpty() && filterModel._InstallAddressIDs.Count > 0)
            {
                where = where.And(x => filterModel._InstallAddressIDs.Contains(x.InstallAddressID));
            }
            if (filterModel._NotInstallAddressIDs.IsNotEmpty() && filterModel._NotInstallAddressIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotInstallAddressIDs.Contains(x.InstallAddressID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //编码
            if (!string.IsNullOrEmpty(filterModel._Code))
            {
                where = where.And(x => x.Code.Contains(filterModel._Code));
            }
            if (!string.IsNullOrEmpty(filterModel._CodeEqual))
            {
                where = where.And(x => x.Code == filterModel._CodeEqual);
            }

            //是否删除
            if (filterModel._IsDelete.HasValue)
            {
                where = where.And(x => x.IsDelete == filterModel._IsDelete.Value);
            }
            if (filterModel._IsDeletes.IsNotEmpty() && filterModel._IsDeletes.Count > 0)
            {
                where = where.And(x => filterModel._IsDeletes.Contains(x.IsDelete));
            }
            
            //创建人姓名
            if (!string.IsNullOrEmpty(filterModel._CreateUserName))
            {
                where = where.And(x => x.CreateUserName.Contains(filterModel._CreateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CreateUserNameEqual))
            {
                where = where.And(x => x.CreateUserName == filterModel._CreateUserNameEqual);
            }

            //创建时间
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            //修改人姓名
            if (!string.IsNullOrEmpty(filterModel._UpdateUserName))
            {
                where = where.And(x => x.UpdateUserName.Contains(filterModel._UpdateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._UpdateUserNameEqual))
            {
                where = where.And(x => x.UpdateUserName == filterModel._UpdateUserNameEqual);
            }

            //修改时间
            if (filterModel._UpdateDate.HasValue)
            {
                where = where.And(x => x.UpdateDate == filterModel._UpdateDate.Value);
            }
            if (filterModel._UpdateDate_Begin.HasValue)
            {
                where = where.And(x => x.UpdateDate >= filterModel._UpdateDate_Begin.Value);
            }
            if (filterModel._UpdateDate_End.HasValue)
            {
                where = where.And(x => x.UpdateDate < filterModel._UpdateDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

